package com.aaa.controller;

import com.aaa.dao.PublisherMapper;
import com.aaa.entity.Publisher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("publisher")
public class PublisherController {
    @Resource
    PublisherMapper publisherMapper;

    @RequestMapping("find")
    public List<Publisher> find(){
        return publisherMapper.find();
    }

    @RequestMapping("add")
    @ResponseBody
    public int add(Publisher publisher){
        return publisherMapper.add(publisher);
    }

    @RequestMapping("update")
    @ResponseBody
    public int update(Publisher publisher){
        return publisherMapper.update(publisher);
    }

    @RequestMapping("delete")
    @ResponseBody
    public int delete(Integer id){
        return publisherMapper.delete(id);
    }


    @ResponseBody
    @RequestMapping("findpage")
    public Map<String, Object> find(Integer pageSize, Integer pageNum){
        Map<String, Object> map = new HashMap<>();
        List<Publisher> userList = publisherMapper.findpage(pageSize, pageSize*pageNum );
        Integer TotalNum = publisherMapper.findcount();
        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }
}
